#pragma once

#include<iostream>
#include<vector>
#include<time.h>
// 将 PrintLog、Download、Upload 注册到 func_t 类型的容器中
// 例如在 main 或 TaskManager 构造函数中调用 Resgister_task(PrintLog);
// Resgister_task(Download);
// Resgister_task(Upload);
typedef void (*func_t)();

void PrintLog()
{
    std::cout<<"打印日志"<<std::endl;
}


void Download()
{
    std::cout<<"下载文件"<<std::endl;
}
void Upload()
{
    std::cout<<"上传文件"<<std::endl;
}
class TaskManager
{
public:
    TaskManager()
    {
        srand((unsigned long)time(NULL));
    }
    void Resgister_task(func_t t)
    {
        _tasks.push_back(t);
    }
    int Code()
    {
        return rand()%_tasks.size();
    }
    void Execute(int code)
    {
        if(code >= 0 && code < (int)_tasks.size())
        {
            //函数指针的方式调用任务
            _tasks[code]();
        }
        else
        {
            std::cerr<<"任务码错误"<<std::endl;
        }
    }
    ~TaskManager()
    {}

private:
    std::vector <func_t> _tasks;

};